package main

import (
	"context"
	"log"
	"os"
	"os/signal"
	"path/filepath"
	"syscall"

	"gitee.com/go-wena/cli"
	_ "gitee.com/go-wena/env/auto"
)

var (
	executable, _ = os.Executable()
	name          = filepath.Base(executable)
	root          = cli.New(cli.Use(name), cli.Comment("wena app 工具链"))
)

func main() {
	log.SetOutput(os.Stdout)
	log.SetFlags(0)
	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2)
	defer cancel()
	root.Execute(ctx)
}

//func handleRoot() {
//	var options []cli.Option
//	const flagUsage = "日志前缀: 1 年月日, 2 时分秒, 4 毫秒, 8 长文件名, 16 短文件名"
//	options = append(options, cli.PersistentFlags(func(fs *cli.FlagSet) {
//		fs.Int("log.flags", 19, flagUsage)
//	}))
//	options = append(options, cli.PersistentPostRun(func(c *cli.Command, args []string) {
//		logFlags, _ := c.PersistentFlags().GetInt("log.flags")
//		if logFlags > 0 {
//			log.SetFlags(logFlags)
//		}
//	}))
//	for _, option := range options {
//		option.Apply(root)
//	}
//}
